package com.kaishengit.action;

import java.util.List;
import java.util.Map;


import org.apache.struts2.interceptor.SessionAware;

import com.kaishengit.pojo.Task;
import com.kaishengit.pojo.TaskType;
import com.kaishengit.pojo.User;
import com.kaishengit.service.TaskService;
import com.kaishengit.service.TaskTypeService;
import com.kaishengit.util.DateUtil;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class TaskAction extends ActionSupport implements SessionAware{

	
	private static final long serialVersionUID = 1L;
	private TaskService taskService;
	private Task task;
	private List<Task> taskList;
	private User user;
	private List<TaskType> tasktypeList;
	private TaskType taskType;
	private List<Task> tasklondList;
	private Map<String,Object> session;
	private List<TaskType> types;
	
	public String list(){
		
		taskList=taskService.findAll();
		//tasktypeList=taskService.findalltasktype();
		return SUCCESS;
	}
	
	  public String save(){
		  session = ActionContext.getContext().getSession();
			user = (User) session.get("user");
			task.setCreatetime(DateUtil.getNow());
			task.setComplete(true);
			taskService.save(task,user,taskType);
		  return SUCCESS;
	  }
	public String addtask(){
		types=taskService.tasktypeList();
		for(TaskType aa:types){
			System.out.print(aa.getType());
		}
		return SUCCESS;
	}
	
	
	//get set
	public Task getTask() {
		return task;
	}
	public void setTask(Task task) {
		this.task = task;
	}
	public void setTaskService(TaskService taskService) {
		this.taskService = taskService;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public List<Task> getTaskList() {
		return taskList;
	}

	public void setTaskList(List<Task> taskList) {
		this.taskList = taskList;
	}

	public List<TaskType> getTypes() {
		return types;
	}

	public void setTypes(List<TaskType> types) {
		this.types = types;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public TaskService getTaskService() {
		return taskService;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<TaskType> getTasktypeList() {
		return tasktypeList;
	}

	public void setTasktypeList(List<TaskType> tasktypeList) {
		this.tasktypeList = tasktypeList;
	}


	public TaskType getTaskType() {
		return taskType;
	}

	public void setTaskType(TaskType taskType) {
		this.taskType = taskType;
	}

	public List<Task> getTasklondList() {
		return tasklondList;
	}

	public void setTasklondList(List<Task> tasklondList) {
		this.tasklondList = tasklondList;
	}

	

	
	
	

}
